
<!DOCTYPE html>
<html lang="zh" class="loading">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>浅尝C艹艹 - 二月の档案室</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate" />
    <meta name="keywords" content="二月,"> 
    <meta name="description" content="所感所想，所言所行，我将以文字记录我自己。,123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354,"> 
    <meta name="author" content="Allureluoli"> 
    <link rel="alternative" href="atom.xml" title="二月の档案室" type="application/atom+xml"> 
    <link rel="icon" href="/img/favicon.png"> 
    
    
    
    <meta name="twitter:card" content="summary"/>
    <meta name="twitter:title" content="浅尝C艹艹 - 二月の档案室"/>
    <meta name="twitter:description" content="所感所想，所言所行，我将以文字记录我自己。,123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354,"/>
    
    
    
    
    <meta property="og:site_name" content="二月の档案室"/>
    <meta property="og:type" content="object"/>
    <meta property="og:title" content="浅尝C艹艹 - 二月の档案室"/>
    <meta property="og:description" content="所感所想，所言所行，我将以文字记录我自己。,123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354,"/>
    
<link rel="stylesheet" href="/css/diaspora.css">

    <script>window.searchDbPath = "/search.xml";</script>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<meta name="generator" content="Hexo 6.3.0"></head>

<body class="loading">
    <span id="config-title" style="display:none">二月の档案室</span>
    <div id="loader"></div>
    <div id="single">
    <div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <a class="iconfont icon-home image-icon" href="javascript:;" data-url="http://example.com"></a>
    <div title="播放/暂停" class="iconfont icon-play"></div>
    <h3 class="subtitle">浅尝C艹艹</h3>
    <div class="social">
        <div>
            <div class="share">
                <a title="获取二维码" class="iconfont icon-scan" href="javascript:;"></a>
            </div>
            <div id="qr"></div>
        </div>
    </div>
    <div class="scrollbar"></div>
</div>

    <div class="section">
        <div class="article">
    <div class='main'>
        <h1 class="title">浅尝C艹艹</h1>
        <div class="stuff">
            <span>三月 15, 2023</span>
            
  <ul class="post-tags-list" itemprop="keywords"><li class="post-tags-list-item"><a class="post-tags-list-link" href="/tags/C/" rel="tag">C#</a></li><li class="post-tags-list-item"><a class="post-tags-list-link" href="/tags/%E5%9F%BA%E7%A1%80/" rel="tag">基础</a></li></ul>


        </div>
        <div class="content markdown">
            <figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> Microsoft.Win32;</span><br><span class="line"><span class="keyword">using</span> System;<span class="comment">//unsing指令 让我们的程序包含System的应用空间</span></span><br><span class="line"><span class="keyword">using</span> System.Threading.Channels;</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> <span class="title">HelloWorldApplication</span> &#123;<span class="comment">//声明了一个 命名空间</span></span><br><span class="line">    <span class="keyword">class</span> <span class="title">Recttangle</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="built_in">double</span> length;</span><br><span class="line">        <span class="built_in">double</span> width;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">Acceptdetails</span>()</span></span><br><span class="line">        &#123;</span><br><span class="line">            length = <span class="number">4.5</span>;</span><br><span class="line">            width = <span class="number">3.5</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="built_in">double</span> <span class="title">GetArea</span>()</span></span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">return</span> length * width;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">Display</span>()</span></span><br><span class="line">        &#123;</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;Length:&#123;0&#125;&quot;</span>, length);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;Width:&#123;0&#125;&quot;</span>, width);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;Area:&#123;0&#125;&quot;</span>, GetArea());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">class</span> <span class="title">Helloworld</span><span class="comment">//声明了一个 类</span></span><br><span class="line">    &#123;                <span class="comment">//</span></span><br><span class="line">        <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Main</span>(<span class="params"><span class="built_in">string</span>[] args</span>)<span class="comment">//这里是Main方法，C#程序的入口点</span></span></span><br><span class="line">        &#123;       <span class="comment">//顺带一提，Static 是静态 Void是空，也就输静态空</span></span><br><span class="line">            <span class="comment">//为什么用静态空？原因很简单，这里是主方法，TA不需要返回任何值给谁，所以使用静态空</span></span><br><span class="line">            <span class="comment">/* C#练习 */</span></span><br><span class="line">            Console.WriteLine(<span class="string">&quot;你好，C#！&quot;</span>);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;你好，Visual Studio!&quot;</span>);</span><br><span class="line">            <span class="comment">//vs直接敲cw就可以出现 Console.WriteLine了</span></span><br><span class="line">            <span class="comment">//WriteLine 是一个定义在 System 命名空间中的 Console 类的一个方法</span></span><br><span class="line">            Recttangle r = <span class="keyword">new</span> Recttangle();<span class="comment">//实例化这个类  盲猜是因为同一文件，所以就可以直接实例化上面那个类</span></span><br><span class="line">            r.Acceptdetails();<span class="comment">//调用方法</span></span><br><span class="line">            r.Display();<span class="comment">//方法</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">            <span class="comment">//C#的数据类型</span></span><br><span class="line">            <span class="comment">//bool byte char decimal double float int long sbyte short uint ulong ushort</span></span><br><span class="line">            <span class="comment">//无符号整数被减会怎么样呢？</span></span><br><span class="line">            <span class="comment">//不同类型的数字可以一起运算吗？</span></span><br><span class="line">            <span class="built_in">bool</span> BoolOne = <span class="literal">true</span>;</span><br><span class="line">            <span class="built_in">byte</span> ByteOne = <span class="number">6</span>, ByteTwo = <span class="number">5</span>;</span><br><span class="line">            <span class="built_in">char</span> CharOne = <span class="string">&#x27;a&#x27;</span>;</span><br><span class="line">            <span class="built_in">char</span> CharTwo = <span class="string">&#x27;b&#x27;</span>;</span><br><span class="line">            <span class="built_in">decimal</span> DecimalOne = <span class="number">0.0</span>M;</span><br><span class="line">            <span class="built_in">double</span> DoubleOne = <span class="number">111.111</span>;</span><br><span class="line">            <span class="built_in">float</span> FloatOne = <span class="number">111.111F</span>;</span><br><span class="line">            <span class="built_in">int</span> IntOne = <span class="number">111</span>;</span><br><span class="line">            <span class="built_in">long</span> LongOne = <span class="number">111</span>;</span><br><span class="line">            <span class="built_in">sbyte</span> SbyleOne = <span class="number">127</span>;</span><br><span class="line">            <span class="built_in">short</span> ShortOne = <span class="number">3456</span>;</span><br><span class="line">            <span class="built_in">uint</span> UintOne = <span class="number">111</span>;</span><br><span class="line">            <span class="built_in">ulong</span> ulongOne = <span class="number">222</span>;</span><br><span class="line">            <span class="built_in">ushort</span> ushortOne = <span class="number">333</span>;</span><br><span class="line"></span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是布尔类型:&quot;</span>+BoolOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是byte类型：&quot;</span>+ByteOne+ByteTwo);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是字符类型:&quot;</span>+CharOne+CharTwo);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是decimal类型：&quot;</span>+DecimalOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是Double类型：&quot;</span>+DoubleOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是Folat类型：&quot;</span>+FloatOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是Int类型：&quot;</span>+IntOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是long类型：&quot;</span>+LongOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是sbyte类型：&quot;</span>+SbyleOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是short类型：&quot;</span>+ShortOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是unit类型：&quot;</span>+UintOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是ulong类型:&quot;</span>+ulongOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;这是ushort类型:&quot;</span>+ushortOne);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;\n&quot;</span>);<span class="comment">//由于本身WirteLine就自动带一个\n，这样子就一下子空两行了。</span></span><br><span class="line"></span><br><span class="line">            <span class="built_in">double</span> DoubleThree = <span class="number">3.3333</span>;</span><br><span class="line">            <span class="comment">//先声明再初始化是良好的写法。</span></span><br><span class="line">            <span class="built_in">int</span> NumberOne;</span><br><span class="line">            <span class="built_in">int</span> NumberTwo;</span><br><span class="line">            <span class="built_in">int</span> NumberThree;</span><br><span class="line"></span><br><span class="line">            NumberOne=<span class="number">111</span>;</span><br><span class="line">            NumberTwo=<span class="number">222</span>;</span><br><span class="line">            NumberThree=<span class="number">333</span>;</span><br><span class="line"></span><br><span class="line">            Console.WriteLine(<span class="string">&quot;随便输出几个数字:&quot;</span>+NumberOne+NumberTwo+NumberThree);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;随便输出一个强制类型转换的数字:&quot;</span>+(<span class="built_in">int</span>)DoubleThree);</span><br><span class="line"></span><br><span class="line">            Console.WriteLine(<span class="string">&quot;输出字符串&#123;0&#125;&quot;</span>, <span class="string">&quot;啊输出字符串&quot;</span>);</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;浅记一下逻辑运算符：&quot;</span>);</span><br><span class="line"></span><br><span class="line">            <span class="built_in">bool</span> BoolTwo = <span class="literal">false</span>;</span><br><span class="line">            <span class="built_in">bool</span> BoolThree = <span class="literal">false</span>;</span><br><span class="line">            <span class="built_in">bool</span> BoolFour = <span class="literal">false</span>;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (NumberThree&gt;NumberTwo)</span><br><span class="line">            &#123;</span><br><span class="line">                BoolTwo = <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (NumberTwo&gt;NumberOne)</span><br><span class="line">            &#123;</span><br><span class="line">                BoolFour = <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            Console.WriteLine(BoolFour&amp;&amp;BoolTwo);</span><br><span class="line">            Console.WriteLine(BoolFour&amp;&amp;BoolThree);</span><br><span class="line">            Console.WriteLine(BoolFour||BoolThree);</span><br><span class="line">            Console.WriteLine(!(BoolTwo &amp;&amp; BoolThree));</span><br><span class="line">            <span class="comment">//差不多就这样了 ，接下来是位运算</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//One = 0011 1100</span></span><br><span class="line">            <span class="comment">//Two = 0000 1101</span></span><br><span class="line">            <span class="built_in">int</span> BitwiseNumberOne = <span class="number">60</span>;</span><br><span class="line">            <span class="built_in">int</span> BitwiseNumberTwo = <span class="number">13</span>;</span><br><span class="line"></span><br><span class="line">            Console.WriteLine(BitwiseNumberOne&amp;BitwiseNumberTwo);<span class="comment">// 0000 1100 对每位执行AND运算符</span></span><br><span class="line">            Console.WriteLine(BitwiseNumberOne|BitwiseNumberTwo);<span class="comment">// 0011 1101 对每位执行OR运算符</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//什么是AND运算符 1 AND 1 = 1 1 AND 0 = 0 0 AND 1 = 0 0 AND 0 = 0</span></span><br><span class="line">            <span class="comment">//什么是OR运算符  1 OR 1 = 1 1 OR 0 = 1 0 OR 1 = 1 O OR O = 0</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//浅浅的写一下switch语句</span></span><br><span class="line">            <span class="built_in">int</span> NumberFive = <span class="number">1</span>;</span><br><span class="line">            <span class="keyword">switch</span> (NumberFive)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">                    Console.WriteLine(<span class="string">&quot;这个数字是1&quot;</span>);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">                    Console.WriteLine(<span class="string">&quot;传透过来了。&quot;</span>);<span class="comment">//这里像写一下穿透的示例，但是C#居然是禁止穿透的，233333</span></span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line">                    Console.WriteLine(<span class="string">&quot;但是问题不大哦&quot;</span>);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="literal">default</span>:</span><br><span class="line">                    Console.WriteLine(<span class="string">&quot;233333&quot;</span>);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                    <span class="comment">//如果不满足以上任何标签的条件，则执行default块的内容</span></span><br><span class="line">                    <span class="comment">//switch语句最后一行也要记得加break语句，否则无法脱离开关</span></span><br><span class="line">                    <span class="comment">//是否可以return一个函数呢？</span></span><br><span class="line">            &#125;       <span class="comment">//我认为是有可能的。</span></span><br><span class="line"></span><br><span class="line">            <span class="keyword">switch</span> (NumberFive)<span class="comment">//这里填变量就不会出现这个错误，如果直接填数字，编译器则会发现一个多余的case代码，它是不会被执行的，所以就会报一个警告</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">case</span> <span class="number">0</span>:</span><br><span class="line">                    Console.WriteLine(<span class="string">&quot;还有吗&quot;</span>);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="comment">//这样写会有一个不影响编译的警告：warning CS0162: 检测到无法访问的代码</span></span><br><span class="line">                <span class="comment">//原因是：在switch语句中，没有匹配到执行的 case 中</span></span><br><span class="line">                <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line"></span><br><span class="line">                    Console.WriteLine(<span class="string">&quot;哈哈哈&quot;</span>);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="built_in">int</span> WhileNmuber = <span class="number">3</span>;</span><br><span class="line">            <span class="keyword">while</span> (WhileNmuber&gt;<span class="number">0</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                WhileNmuber--;</span><br><span class="line">                Console.WriteLine(<span class="string">&quot;减减&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//接下来是for循环捏</span></span><br><span class="line">            <span class="comment">//for ( init; condition; increment )</span></span><br><span class="line">            <span class="comment">//语法如上，意思就是，for (初始化；判断；increment )</span></span><br><span class="line">            <span class="comment">//执行完 init 执行 condition 执行完 condition 执行循环主体 执行完循环主体 执行increment</span></span><br><span class="line">            <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i&lt;<span class="number">3</span>;)</span><br><span class="line">            &#123;</span><br><span class="line">                i++;</span><br><span class="line">                Console.WriteLine(<span class="string">&quot;原来是这样！&quot;</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//foreach循环语句</span></span><br><span class="line">            <span class="comment">//使用foreach可以迭代数组或者一个集合对象。</span></span><br><span class="line">            <span class="comment">//什么是迭代？ 迭代是重复反馈过程的活动，其目的通常是为了逼近所需目标或结果......</span></span><br><span class="line">            <span class="comment">//说人话：执行程序中的循环，直到满足某条件为止，亦称为迭代。</span></span><br><span class="line">            <span class="built_in">int</span>[] fibarray = <span class="keyword">new</span> <span class="built_in">int</span>[] &#123; <span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>, <span class="number">13</span> &#125;;<span class="comment">//创建一个整型数组</span></span><br><span class="line">            <span class="keyword">foreach</span> (<span class="built_in">int</span> element <span class="keyword">in</span> fibarray)<span class="comment">//变量elementu遍历整个数组</span></span><br><span class="line"></span><br><span class="line">            &#123;</span><br><span class="line">                System.Console.WriteLine(element);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">//元素计算器 ：很简单的实现方式</span></span><br><span class="line">            <span class="built_in">int</span> count = <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">foreach</span> (<span class="built_in">int</span> element <span class="keyword">in</span> fibarray)</span><br><span class="line">            &#123;</span><br><span class="line">                count += <span class="number">1</span>;</span><br><span class="line">                System.Console.WriteLine(<span class="string">&quot;Element #&#123;0&#125;: &#123;1&#125;:&#123;2&#125;&quot;</span>, count, element, <span class="string">&quot;我去&quot;</span>, <span class="string">&quot;2333&quot;</span>);</span><br><span class="line">            &#125;                               <span class="comment">//两个占位符，表示后面有两个需要输出的代码，而且占位符无关位置</span></span><br><span class="line">                                            <span class="comment">//值得一提的是，如果多写了一个占位符，程序会直接崩溃，如果少写了一个占位符，仅仅只会少输出后面部分的内容</span></span><br><span class="line">                                            <span class="comment">//接下来是，Do while循环~</span></span><br><span class="line">                                            <span class="comment">//理解很简单，就是先执行一次，再从尾部检查条件，再判断是否执行。</span></span><br><span class="line">            <span class="keyword">do</span></span><br><span class="line">            &#123;</span><br><span class="line">                Console.WriteLine(<span class="string">&quot;欸嘿我先执行一次辣~&quot;</span>);</span><br><span class="line">            &#125; <span class="keyword">while</span> (<span class="number">0</span>&gt;<span class="number">1</span>);<span class="comment">//逆天写法</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//哦对，C#中的循环也是可以嵌套的，不过我懒得写了。</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//接下来是封装</span></span><br><span class="line">            <span class="comment">//神马是封装？封装 被定义为&quot;把一个或多个项目封闭在一个物理的或者逻辑的包中&quot;。</span></span><br><span class="line">            <span class="comment">//封装的意义：在面向对象程序设计方法论中，封装是为了防止对实现细节的访问。</span></span><br><span class="line">            <span class="comment">//抽象和封装是面向对象程序设计的相关特性。抽象允许相关信息可视化，封装则使开发者实现所需级别的抽象。</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//如下是访问修饰符</span></span><br><span class="line">            <span class="comment">/*一个 访问修饰符 定义了一个类成员的范围和可见性。C# 支持的访问修饰符如下所示：</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">                   public：所有对象都可以访问；</span></span><br><span class="line"><span class="comment">                   private：对象本身在对象内部可以访问；</span></span><br><span class="line"><span class="comment">                   protected：只有该类对象及其子类对象可以访问</span></span><br><span class="line"><span class="comment">                   internal：同一个程序集的对象可以访问；</span></span><br><span class="line"><span class="comment">                   protected internal：访问限于当前程序集或派生自包含类的类型。</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">            */</span></span><br><span class="line">            <span class="comment">//public中，即使是在一个类中，也可以通过public将函数暴露给其他成员</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//Private 访问修饰符允许一个类将其成员变量和成员函数对其他的函数和对象进行隐藏。只有同一个类中的函数可以访问它的私有成员。即使是类的实例也不能访问它的私有成员。</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//Protected 访问修饰符 Protected 访问修饰符允许子类访问它的基类的成员变量和成员函数。这样有助于实现继承。</span></span><br><span class="line">            <span class="comment">//什么是基类和成员函数呢？</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//Internal 访问修饰符 Internal 访问修饰符允许一个类将其成员变量和成员函数暴露给当前程序中的其他函数和对象。</span></span><br><span class="line">            <span class="comment">//当前函数的</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//接下来是 方法 捏~</span></span><br><span class="line">            <span class="comment">//&lt;Access Specifier&gt; &lt;Return Type&gt; &lt;Method Name&gt;(Parameter List)</span></span><br><span class="line">            <span class="comment">//格式如上</span></span><br><span class="line">            <span class="comment">//修饰符 返回类型 （不返回值的为void哦~） 方法名称 (括号里的参数捏)</span></span><br><span class="line">            <span class="comment">//欸嘿方法很简单辣</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//懒得写代码了~</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//递归方法调用</span></span><br><span class="line">            <span class="comment">//神马是递归呢 一个方法可以自我调用就是递归捏！</span></span><br><span class="line">            NumberManipulator n = <span class="keyword">new</span> NumberManipulator();</span><br><span class="line">            Console.WriteLine(<span class="string">&quot;6 的阶乘是： &#123;0&#125;&quot;</span>, n.factorial(<span class="number">6</span>));</span><br><span class="line"></span><br><span class="line">            <span class="built_in">int</span> NmubernullOne;<span class="comment">//这个默认为0</span></span><br><span class="line">            <span class="built_in">int</span>? NmubernullTwo;<span class="comment">//进行Null赋值，这个默认为null</span></span><br><span class="line">            Console.WriteLine();</span><br><span class="line">            <span class="comment">//被赋予了null 值的类型，称为可空类型，就是可以变成null的类型</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//合并运算符 ??</span></span><br><span class="line">            <span class="comment">//如果第一个操作数的值为 null，则运算符返回第二个操作数的值，否则返回第一个操作数的值。下面的实例演示了这点：</span></span><br><span class="line">            <span class="built_in">double</span>? num1 = <span class="literal">null</span>;</span><br><span class="line">            <span class="built_in">double</span>? num2 = <span class="number">3.14157</span>;</span><br><span class="line">            <span class="built_in">double</span>? num3 = <span class="keyword">new</span> <span class="built_in">double</span>?();</span><br><span class="line">            num3 = num1 ?? num2;</span><br><span class="line">            Console.WriteLine(num3);</span><br><span class="line">            Console.WriteLine(num1 ?? num2);</span><br><span class="line">            <span class="comment">//C# 提供了一个特殊的数据类型，nullable 类型（可空类型），可空类型可以表示其基础值类型正常范围内的值，再加上一个 null 值。</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//正好想到了，C#中上半部分的程序是否可以调用下半部分程序的方法呢</span></span><br><span class="line">            <span class="comment">//可是程序都是逐行阅读的来着？</span></span><br><span class="line">            <span class="comment">//经过实验，C#中是可以的，Python中我忘了行不行了</span></span><br><span class="line">            <span class="comment">//经过实验，Python中是不行的，因为Python是逐行阅读代码的脚本语言</span></span><br><span class="line">            <span class="comment">//这是一个处理数字的类，可以用来计算数学中的阶乘</span></span><br><span class="line"></span><br><span class="line">            <span class="comment">//C#的数组</span></span><br><span class="line">            <span class="comment">//注意，数组不可以重复声明</span></span><br><span class="line">            <span class="comment">//声明一个数组</span></span><br><span class="line">            <span class="built_in">double</span>[] balanceOne;</span><br><span class="line">            <span class="comment">//声明一个数组不会在内存中初始化数组</span></span><br><span class="line">            <span class="built_in">double</span>[] balance = <span class="keyword">new</span> <span class="built_in">double</span>[<span class="number">10</span>];<span class="comment">//声明数组的长度</span></span><br><span class="line">            balance[<span class="number">0</span>] = <span class="number">4500.0</span>;<span class="comment">//然后单独赋值</span></span><br><span class="line"></span><br><span class="line">            <span class="built_in">double</span>[] balanceThree = &#123; <span class="number">2340.0</span>, <span class="number">4523.69</span>, <span class="number">3421.0</span> &#125;;<span class="comment">//声明的时候给数组赋值</span></span><br><span class="line"></span><br><span class="line">            <span class="built_in">int</span>[] marksOne = <span class="keyword">new</span> <span class="built_in">int</span>[<span class="number">5</span>] &#123; <span class="number">99</span>, <span class="number">98</span>, <span class="number">92</span>, <span class="number">97</span>, <span class="number">95</span> &#125;;<span class="comment">//可以创建并初始化一个数组</span></span><br><span class="line"></span><br><span class="line">            <span class="built_in">int</span>[] marksTwo = <span class="keyword">new</span> <span class="built_in">int</span>[] &#123; <span class="number">99</span>, <span class="number">98</span>, <span class="number">92</span>, <span class="number">97</span>, <span class="number">95</span> &#125;;<span class="comment">//可以省略数组的大小</span></span><br><span class="line"></span><br><span class="line">            <span class="built_in">int</span>[] marksThree = <span class="keyword">new</span> <span class="built_in">int</span>[] &#123; <span class="number">99</span>, <span class="number">98</span>, <span class="number">92</span>, <span class="number">97</span>, <span class="number">95</span> &#125;;<span class="comment">//可以将一个数组变量赋值给另一个数组变量</span></span><br><span class="line">            <span class="built_in">int</span>[] score = marksThree;</span><br><span class="line"></span><br><span class="line">            <span class="comment">/*</span></span><br><span class="line"><span class="comment">            创建字符串的五种方法</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">            通过给 String 变量指定一个字符串</span></span><br><span class="line"><span class="comment">            通过使用 String 类构造函数</span></span><br><span class="line"><span class="comment">            通过使用字符串串联运算符（ + ）</span></span><br><span class="line"><span class="comment">            通过检索属性或调用一个返回字符串的方法</span></span><br><span class="line"><span class="comment">            通过格式化方法来转换一个值或对象为它的字符串表示形式</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">            */</span></span><br><span class="line"></span><br><span class="line">            String StringOne;</span><br><span class="line">            <span class="built_in">string</span> stringOne;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    </span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">             Console.ReadKey();<span class="comment">//这使得程序会等待一个按键的动作，防止程序从 Visual Studio .NET 启动时屏幕会快速运行并关闭。</span></span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="comment">//枚举</span></span><br><span class="line">        <span class="comment">//什么是枚举</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="comment">//包含很多变量的集合，可以调用集合</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">/*</span></span><br><span class="line"><span class="comment">         C#的枚举类型(Enum)是用来定义变量，这些变量表示一组人工定义的常量。使用枚举允许程序员有效地标识变量，并更容易地处理枚举值。例如，一个颜色枚举类型可以包括红、绿、蓝等常量值。</span></span><br><span class="line"><span class="comment"> </span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line"></span><br><span class="line">        <span class="built_in">enum</span> EnmuOne &#123; One, Two, Three, Four &#125;;</span><br><span class="line">        <span class="built_in">int</span> x = (<span class="built_in">int</span>)EnmuOne.One;</span><br><span class="line">        <span class="built_in">int</span> y = (<span class="built_in">int</span>)EnmuOne.Two;</span><br><span class="line">        <span class="comment">//枚举是这样的</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title">NumberManipulator</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="built_in">int</span> <span class="title">factorial</span>(<span class="params"><span class="built_in">int</span> num</span>)</span></span><br><span class="line">        &#123;</span><br><span class="line">            <span class="comment">/* 局部变量定义 */</span></span><br><span class="line">            <span class="built_in">int</span> result;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (num == <span class="number">1</span>)<span class="comment">//仅在num等于1的时候返回1让循环终止</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                result = factorial(num - <span class="number">1</span>) * num;</span><br><span class="line">                <span class="keyword">return</span> result;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>


            <!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
            <audio id="audio" loop="1" preload="auto" controls="controls" data-autoplay="true">
                <source type="audio/mpeg" src="">
            </audio>
            
                <ul id="audio-list" style="display:none">
                    
                        
                            <li title="0" data-url="https://webfs.ali.kugou.com/202307041713/4c5c9c66054ff1b1e920cbadbb47ec17/v2/c39d8792fe8a2cd84414ee5d2642f870/G199/M03/1B/10/p5QEAF4oPP-AUpsZACo25HetF6U984.mp3"></li>
                        
                    
                        
                            <li title="1" data-url="https://webfs.ali.kugou.com/202307041713/4c5c9c66054ff1b1e920cbadbb47ec17/v2/c39d8792fe8a2cd84414ee5d2642f870/G199/M03/1B/10/p5QEAF4oPP-AUpsZACo25HetF6U984.mp3"></li>
                        
                    
                </ul>
            
        </div>
        
        
    <div id="gitalk-container" class="comment link"
		data-enable="false"
        data-ae="false"
        data-ci=""
        data-cs=""
        data-r=""
        data-o=""
        data-a=""
        data-d="false"
    >查看评论</div>


    </div>
    
</div>


    </div>
</div>
</body>


<script src="//lib.baomitu.com/jquery/1.8.3/jquery.min.js"></script>
<script src="/js/plugin.js"></script>
<script src="/js/typed.js"></script>
<script src="/js/diaspora.js"></script>


<link rel="stylesheet" href="/photoswipe/photoswipe.css">
<link rel="stylesheet" href="/photoswipe/default-skin/default-skin.css">


<script src="/photoswipe/photoswipe.min.js"></script>
<script src="/photoswipe/photoswipe-ui-default.min.js"></script>


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>






</html>
